<template>
	<view class="logbox">
		<view class="xiaohei fonweight" style="font-size: 56rpx;">注册</view>
		<view class="bigtext xiaohui margin_top5">已注册账号！立即
			<text class="bigtext xiaolan fonweight" @click="back()">登录</text>
		</view>
		<view class="xiahuaxian margin_top6">
			<input type="number" placeholder="请输入手机号" v-model="mobile">
		</view>
		<view class="xiahuaxian margin_top flexbetween">
			<input type="number" placeholder="请输入验证码" v-model="yzm_code">
			<view class="strongtext xiaolan textcenter" style="min-width: 200rpx;" @click="sendyzm" v-show="codetext == 1">
				获取验证码</view>
			<view class="strongtext xiaolan textcenter" style="min-width: 200rpx;" v-show="codetext == 2">{{second}}s后重新获取
			</view>
			<view class="strongtext xiaolan textcenter" style="min-width: 200rpx;" @click="sendyzm" v-show="codetext == 3">
				重新发送</view>
		</view>
		<!-- <view class="xiahuaxian margin_top">
			<input type="password" placeholder="请设置密码" v-model="password">
		</view> -->
		<view class="xiahuaxian margin_top">
			<input type="text" placeholder="请输入邀请码(选填)" v-model="invite_code">
		</view>
		<view class="margin_top6 denglhbtn flexcenter" @click="signIn()">确定</view>
		<view class="gudingdb ffffff mainpadding"  @click="type = !type">
			<view class="flexcenter">
				<!-- 已选中 -->
				<view class="margin_right1"  v-show="type">
					<u-icon name="checkmark-circle-fill" color="#2979ff" size="16"></u-icon>
				</view>
				<!-- 为选中 -->
				<view class="weixz margin_right1"  v-show="!type"></view>
				<view class="flexleft">
					<view class="strongtext xiaohui">我已阅读并同意本平台</view>
					<view class="strongtext xiaolan fonweight" @click.stop="jumper('/pages/system/system?type=1')">用户协议
					</view>
					<view class="strongtext xiaohui">和</view>
					<view class="strongtext xiaolan fonweight" @click.stop="jumper('/pages/system/system?type=2')">隐私协议
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	// #ifdef APP-PLUS
	const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
	// #endif
	export default {
		data() {
			return {
				type:false,
				codetext: 1,
				second: 59,
				mobile: '',
				yzm_code: '',
				password: "",
				pid: uni.getStorageSync("yqrcode") || "",
				invite_code:""
			}
		},
		methods: {

			//验证手机号
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value);
				return a;
			},
			//发送验证码
			sendyzm() {
				let _this = this;
				if (_this.mobile == '') {
					httpRequest.toast("请输入手机号码!")
					return;
				}
				if (!_this.isMobile(_this.mobile)) {
					httpRequest.toast("手机号码格式错误!")
					return;
				}
				httpRequest.request('/api/sms/send', 'POST', {
					mobile: this.mobile,
					event: 'register',
				}, false, true, false).then(res => {
					if (res.code == 1) {
						httpRequest.toast('发送成功')
						_this.codetext = 2;
						_this.second = 59;
						let timer = setInterval(function() {
							if (_this.second > 1) {
								_this.second--;
							} else {
								clearInterval(timer);
								_this.codetext = 3;
							}
						}, 1000)
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
			checkaudio() {
				this.type = !this.type
			},
			signIn() {
				if (this.mobile == "") {
					httpRequest.toast("请输入手机号");
					return false;
				}
				if (!this.isMobile(this.mobile)) {
					httpRequest.toast("手机号码格式错误!")
					return;
				}
				if (this.yzm_code == "") {
					httpRequest.toast("请输入验证码");
					return false;
				}
				// if (this.password == "") {
				// 	httpRequest.toast("请输入密码")
				// 	return false
				// }
				
				if(!this.type){
					httpRequest.toast("请认真阅读并勾选用户协议");
					return false;
				}
				this.liandiantype = 1
				uni.showLoading({
					mask: true,
					title: "请稍候"
				})
				httpRequest.request('/api/user/register', 'GET', {
					mobile: this.mobile,
					code: this.yzm_code,
					// password: this.password,
					invite_code:this.invite_code
				}).then(res => {
					uni.clearStorageSync();
					uni.hideLoading()
					if (res.code == 1) {
						uni.setStorageSync('token',res.data.userinfo.token);
						uni.setStorageSync('user_id',res.data.userinfo.user_id);
						// httpRequest.request('/api/user/profile', 'GET', {online:1}).then(res => {})
						this.userinfofn()
						httpRequest.toast('注册成功');
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/login/xuanzexb'
							})
						}, 1000)
					} else {
						this.liandiantype = 0
						httpRequest.toast(res.msg);
					}
				})
			},
			userinfofn() {
				httpRequest.request('/api/user/getUserSig', 'GET', {}).then(res => {
					let user_id = uni.getStorageSync("user_id")
					this.tuicallkitLogin(user_id,res.data.userSig)
				})
			},
			tuicallkitLogin(userId, userSig) {
				console.log(userId, userSig, "555555555555555555555555555")
				const options = {
					SDKAppID: 1600021546, // 请替换为步骤一取到的 SDKAppID
					userID: userId.toString(), // 请替换为您的 UserID
					userSig: userSig.toString(), // 您可以在控制台中计算一个 UserSig 并填在这个位置
				};
				
				TUICallKit.login(options, (res) => {
					if (res.code === 0) {
						console.log('login success》》》》》》腾讯云音视频连接成功');
					} else {
						console.log(`login failed, error message = ${res.msg}`);
					}
				});
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
			back() {
				uni.navigateBack(1)
			},
		}
	}
</script>

<style lang="scss" scoped>

	.denglhbtn {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		width: 590rpx;
		height: 80rpx;
		background: #2361FF;
		border-radius: 52rpx;
	}

	.logbox {
		padding: 180rpx 80rpx 30rpx;
	}
</style>